var mongoose = require('../modules/database.js');
var Schema = mongoose.Schema;

var schema = new Schema({
    teacherNo: {
        type: String,
        default: 1000
    },
    password: {
        type: String,
        default: 123456
    },
    name: {
        type: String,
        default: "",
    },
    identity: {
        type: Number,
        default: 0,
    },
    phoneNum: {
        type: Number,
        default: ''
    }
});
schema.statics = {
    //登录
    login: function (data, cb) {
        var filter = {
            teacherNo: data.account,
            password: data.password
        };
        Model.findOne(filter, function (err, result) {
            if (err) {
                return cb({ code: 201, message: err });
            }
            if (!result) {
                return cb({ code: 201, message: '账号或密码错误！' });
            }
            return cb(null, { code: 200, result });
        })
    },
    //更改密码
    alterpwd: function (data, cb) {
        Model.findOneAndUpdate({ teacherNo: data.account }, { $set: { password: data.password } }, function (err, result) {
            if (err) {
                return cb({ code: 201, message: '重置密码失败！' });
            }
            return cb(null, { code: 200, message: result });
        })
    },
 
};



var Model = mongoose.model('teachers', schema);
module.exports = Model;